package com.zxx.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.zxx.ssm.model.biz.StuLogBiz;
import com.zxx.ssm.model.biz.TeaLogBiz;
import com.zxx.ssm.model.result.BizResponse;
import com.zxx.ssm.service.TeaStuClaLogService;
import com.zxx.ssm.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("teaStuClaLog")
@Controller
public class TeaStuClaLogController {
    @Autowired
    private TeaStuClaLogService teaStuClaLogService;

    @RequestMapping("getTeaList")
    @ResponseBody
    public BizResponse getTeaList(@RequestParam String teaName, @RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "1") int pageSize,
                                  @RequestParam(defaultValue = "teaId") String sort, @RequestParam(defaultValue = "desc") String order){
        if (sort.equals("teaName"))
            sort = "username";
        PaginationUtil.preset(pageNumber, pageSize, sort, order);
        List<TeaLogBiz> employeeBizList = teaStuClaLogService.getTeaList(teaName);
        PageInfo pageInfo = new PageInfo(employeeBizList);
        BizResponse bizResponse = new BizResponse();
        bizResponse.put("teaLog", pageInfo);
        return bizResponse;
    }

    @RequestMapping("getStuList")
    @ResponseBody
    public BizResponse getStuList(@RequestParam String stuName, @RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "1") int pageSize,
                                  @RequestParam(defaultValue = "stuId") String sort, @RequestParam(defaultValue = "desc") String order){
        if (sort.equals("stuName"))
            sort = "username";
        PaginationUtil.preset(pageNumber, pageSize, sort, order);
        List<StuLogBiz> employeeBizList = teaStuClaLogService.getStuList(stuName);
        PageInfo pageInfo = new PageInfo(employeeBizList);
        BizResponse bizResponse = new BizResponse();
        bizResponse.put("stuLog", pageInfo);
        return bizResponse;
    }
}
